package com.zy.web.controller.bs;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zy.entity.bs.Goods;
import com.zy.pojo.query.bs.GoodsQuery;
import com.zy.pojo.vos.common.PageVo;
import com.zy.pojo.vos.common.ResultVo;
import com.zy.service.bs.GoodsService;
import com.zy.web.controller.base.BaseController;
import com.zy.web.utils.ResultUtil;

@RequestMapping({"bs/goods","m/bs/goods"})
@Controller
public class GoodsController extends BaseController {

	@Autowired
	private GoodsService goodsService;

	/**
	 * 分页
 	 * 
 	 * @param goodsQuery
	 * @param start
	 * @param limit
	 * @return
	 */
	@RequestMapping({"pageGoods","front/listGoods"})
	@ResponseBody
	public PageVo pageGoods(GoodsQuery goodsQuery, Integer start, Integer limit) {
		return this.goodsService.pageGoods(goodsQuery, start, limit);
	}

	/**
	 * 新增
	 * 
	 * @param goods
	 * @return
	 */
	@RequestMapping(value = "saveGoods", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo saveGoods(Goods goods) {
		try {
			this.goodsService.saveGoods(goods);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}
	
	/**
	 * 更新
	 * 
	 * @param goods
	 * @return
	 */
	@RequestMapping(value = "updateGoods", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo updateGoods(Goods goods) {
		try {
			this.goodsService.updateGoods(goods);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 删除
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "removeGoods", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo removeGoods(long id) {
		try {
			this.goodsService.removeGoods(id);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 恢复
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "recover", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo recover(long id) {
		try {
			this.goodsService.recover(id);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	@RequestMapping(value = "shelf", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo shelf(Goods goods) {
		try {
			this.goodsService.shelf(goods);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 更新
	 *
	 * @param goods
	 * @return
	 */
	@RequestMapping(value = "obtained", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo obtained(Goods goods) {
		try {
			this.goodsService.cancel(goods);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	@RequestMapping(value = "front/getGoodsInfo")
	@ResponseBody
	public ResultVo getGoodsInfo(Long id) {
		try {
			return ResultUtil.success(goodsService.getByPrimaryKey(id));
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

}